package com.lxiaodd.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lxiaodd.mapper.UserMapper;
import com.lxiaodd.sevice.UserService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.ApiResponse;

@Api(tags = "二：用户信息") 
@Controller
@RequestMapping("TestCont")
public class TestCont {

	@Autowired
	UserMapper userMapper;
	@Autowired
	UserService userService;
	
	@ApiOperation(httpMethod = "GET", value = "个人信息")//swagger 当前接口注解
	@RequestMapping("test")
	@ResponseBody
	public HashMap<String, Object> test(){
		HashMap<String, Object> map=new HashMap<String, Object>();
		map.put("name", "liupeng");
		return map;
	}
	
	@ApiOperation(httpMethod = "GET", value = "个人信息2")//swagger 当前接口注解
	@RequestMapping("testList")
	@ResponseBody
	public List<HashMap<String, Object>> testList(){
		List<HashMap<String, Object>> list=userMapper.findAllUser();
		return list;
	}
	
	@ApiOperation(httpMethod = "GET", value = "个人信息3")//swagger 当前接口注解
	@ApiResponses(value = {
			  @ApiResponse(code = 500, message = "系统错误"),
			  @ApiResponse(code = 500, message = "系统错误")
	})
	@RequestMapping("testid/{id}")
	@ResponseBody
	public HashMap<String, Object> testid(@ApiParam(required = false, name = "id", value = "用户id") @PathVariable(value = "id") int id){
		HashMap<String, Object> map=userMapper.findUserById(id);
		return map;
	}
	
	@RequestMapping(value = "/update", method = RequestMethod.GET)
	@ResponseBody
	public String testUpdate(Map<String,Object> tmap){
		HashMap<String, Object> map=new HashMap<String, Object>();
		map.put("id", 1);
		map.put("password", "sss1122");
		userService.updateUser(map);
		return "ok";
	}
}
